|
mruby 4.0.0
mruby is the lightweight implementation of the Ruby language
|

Go to the source code of this file.
Classes | |
| struct | RException |
| mruby error handling. More... | |
| struct | RBreak |
Macros | |
| #define | MRB_EXC_EXIT 65536 |
| #define | MRB_EXC_EXIT_P(e) |
| #define | MRB_EXC_EXIT_STATUS(mrb, e) |
| #define | MRB_EXC_CHECK_EXIT(mrb, e) |
| #define | mrb_exc_ptr(v) |
| #define | mrb_exc_new_lit(mrb, c, lit) |
| #define | MRB_USE_RBREAK_VALUE_UNION 1 |
| #define | RBREAK_VALUE_TT_MASK ((1 << 8) - 1) |
| #define | MRB_ENSURE(mrb, result_var, func, data) |
| Calls func via mrb_protect_error() and then always executes the user block exactly once. | |
Typedefs | |
| typedef mrb_value | mrb_protect_error_func(mrb_state *mrb, void *userdata) |
| Protect. | |
Functions | |
| void | mrb_sys_fail (mrb_state *mrb, const char *mesg) |
| mrb_value | mrb_exc_new_str (mrb_state *mrb, struct RClass *c, mrb_value str) |
| void | mrb_no_method_error (mrb_state *mrb, mrb_sym id, mrb_value args, const char *fmt,...) |
| static mrb_value | mrb_break_value_get (struct RBreak *brk) |
| static void | mrb_break_value_set (struct RBreak *brk, mrb_value val) |
| void | mrb_clear_error (mrb_state *mrb) |
| Error check. | |
| mrb_bool | mrb_check_error (mrb_state *mrb) |
| mrb_value | mrb_protect_error (mrb_state *mrb, mrb_protect_error_func *body, void *userdata, mrb_bool *error) |
| Protects a C function call from mruby exceptions. | |
| mrb_value | mrb_protect (mrb_state *mrb, mrb_func_t body, mrb_value data, mrb_bool *state) |
| Protect (takes mrb_value for body argument) | |
| mrb_value | mrb_ensure (mrb_state *mrb, mrb_func_t body, mrb_value b_data, mrb_func_t ensure, mrb_value e_data) |
| Ensure. | |
| mrb_value | mrb_rescue (mrb_state *mrb, mrb_func_t body, mrb_value b_data, mrb_func_t rescue, mrb_value r_data) |
| Rescue. | |
| mrb_value | mrb_rescue_exceptions (mrb_state *mrb, mrb_func_t body, mrb_value b_data, mrb_func_t rescue, mrb_value r_data, mrb_int len, struct RClass **classes) |
| Rescue exception. | |
See Copyright Notice in mruby.h
| #define MRB_ENSURE | ( | mrb, | |
| result_var, | |||
| func, | |||
| data ) |
Calls func via mrb_protect_error() and then always executes the user block exactly once.
Even if a global jump (similar to a Ruby exception) occurs within func, the block will be executed, and after the block's completion, the global jump will be re-thrown.
By checking mrb->exc != NULL within the block, you can determine if a global jump occurred in func.
If you want to suppress the global jump and continue processing, use mrb_clear_error(mrb); break;.
Example:
mrb_value result;
MRB_ENSURE(mrb, result, body_func, userdata) {
// This block is always executed (equivalent to Ruby's ensure)
if (mrb->exc) {
// Post-processing when an exception occurs
}
// To ignore the global jump, use `mrb_clear_error(mrb); break;` here
}
| #define MRB_EXC_CHECK_EXIT | ( | mrb, | |
| e ) |
| #define MRB_EXC_EXIT_P | ( | e | ) |
| #define MRB_EXC_EXIT_STATUS | ( | mrb, | |
| e ) |
| #define mrb_exc_new_lit | ( | mrb, | |
| c, | |||
| lit ) |
| #define mrb_exc_ptr | ( | v | ) |
|
extern |
Ensure.
Implemented in the mruby-error mrbgem
|
extern |
Protect (takes mrb_value for body argument)
Implemented in the mruby-error mrbgem
|
extern |
Protects a C function call from mruby exceptions.
This function executes a C function (body) within a protected environment. If an mruby exception occurs during the execution of body, this function catches the exception, sets the error flag, and returns the exception object. Otherwise, it returns the result of the body function and error remains FALSE.
This is crucial for calling mruby-related C functions from within C code that needs to handle potential mruby exceptions gracefully.
| mrb | The mruby state. |
| body | A pointer to the C function to be executed. The function should have the signature: mrb_value func(mrb_state *mrb, void *userdata) |
| userdata | A pointer to arbitrary data that will be passed to the body function. |
| error | A pointer to an mrb_bool that will be set to TRUE if an exception occurred, and FALSE otherwise. Can be NULL if not needed. |
|
extern |
Rescue.
Implemented in the mruby-error mrbgem
|
extern |
Rescue exception.
Implemented in the mruby-error mrbgem